package com.showtao.front.dto;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.showtao.front.domain.Article;
import com.showtao.front.domain.ArticleStatus;
import com.showtao.front.domain.Tag;

@SuppressWarnings("serial")
public class ArticleDto implements Serializable {

    private Long id;
    private String title;
    private ArticleStatus status;
    private String content;
    private Long catalogId;
    private String catalogName;
    private List<Long> tagIds;
    private List<String> tagNames;
    private Date createdAt;
    private String createdBy;
    private Date updatedAt;
    private String updatedBy;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public ArticleStatus getStatus() {
        return status;
    }

    public void setStatus(ArticleStatus status) {
        this.status = status;
    }

    public Long getCatalogId() {
        return catalogId;
    }
    
    public void setCatalogId(Long catalogId) {
        this.catalogId = catalogId;
    }
    
    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getCatalogName() {
        return catalogName;
    }

    public void setCatalogName(String catalogName) {
        this.catalogName = catalogName;
    }

    public List<Long> getTagIds() {
        return tagIds;
    }

    public void setTagIds(List<Long> tagIds) {
        this.tagIds = tagIds;
    }

    public List<String> getTagNames() {
        return tagNames;
    }

    public void setTagNames(List<String> tagNames) {
        this.tagNames = tagNames;
    }

    public Date getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(Date createdAt) {
        this.createdAt = createdAt;
    }

    public String getCreatedBy() {
        return createdBy;
    }

    public void setCreatedBy(String createdBy) {
        this.createdBy = createdBy;
    }

    public Date getUpdatedAt() {
        return updatedAt;
    }

    public void setUpdatedAt(Date updatedAt) {
        this.updatedAt = updatedAt;
    }

    public String getUpdatedBy() {
        return updatedBy;
    }

    public void setUpdatedBy(String updatedBy) {
        this.updatedBy = updatedBy;
    }

    public static ArticleDto from(Article entity){
        ArticleDto dto = new ArticleDto();
        dto.setId(entity.getId());
        dto.setTitle(entity.getTitle());
        dto.setStatus(entity.getStatus());
        dto.setContent(entity.getContent());
        if(entity.getCatalog()!= null){
            dto.setCatalogId(entity.getCatalog().getId());
            dto.setCatalogName(entity.getCatalog().getName());
        }
        if(entity.getTags()!=null){
            List<Long> tagIds = new ArrayList<Long>();
            List<String> tagNames = new ArrayList<String>();
            for(Tag tag: entity.getTags()){
                tagIds.add(tag.getId());
                tagNames.add(tag.getName());
            }
            dto.setTagIds(tagIds);
            dto.setTagNames(tagNames);
        }
        dto.setCreatedAt(entity.getCreatedAt());
        dto.setUpdatedAt(entity.getUpdatedAt());
        dto.setCreatedBy(entity.getCreatedBy());
        dto.setUpdatedBy(entity.getUpdatedBy());
        return dto;
    }
}
